package com.doupi.partner.util;

import com.doupi.partner.util.constant.UtilConstants;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serializable;
import java.util.Date;

/**
 * API返回类
 */
public class AjaxResponse implements Serializable {

	private static final long serialVersionUID = -862002418159896221L;

	// 成功消息提示
	private static final String SUCCESS_MESSAGE = "成功";

	/**
	 * 响应码
	 */
	private String statusCode;

	/**
	 * 响应消息
	 */
	private String message;

	/**
	 * 响应时间
	 */
	private Date responseTime;

	/**
	 * 响应业务
	 */
	private String biz;

	/**
	 * TODO 平台code 平台 HTML5 ANDROID IOS PC WEB
	 */
	private String platform;

	/**
	 * token 校验成功重新设置
	 */
	private String token;

	/**
	 * 响应数据
	 */
	private Object data;

	public AjaxResponse(String statusCode, String message) {
		this.statusCode = statusCode;
		this.message = message;
	}

	public AjaxResponse(Object data) {
		this.data = data;
		this.statusCode = UtilConstants.SUCCESS_STATUS_CODE;
		this.message = SUCCESS_MESSAGE;
	}

	public static AjaxResponse defaultResponse() {
		return new AjaxResponse(UtilConstants.SUCCESS_STATUS_CODE, SUCCESS_MESSAGE);
	}

	public String getStatusCode() {
		return statusCode;
	}

	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Date getResponseTime() {
		return responseTime;
	}

	public void setResponseTime(Date responseTime) {
		this.responseTime = responseTime;
	}

	public String getBiz() {
		return biz;
	}

	public void setBiz(String biz) {
		this.biz = biz;
	}

	public String getPlatform() {
		return platform;
	}

	public void setPlatform(String platform) {
		this.platform = platform;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public void setStatusCodeAndMessage(String statusCode, String message) {
		this.statusCode = statusCode;
		this.message = message;
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj);
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
	}
}
